// setInterval
let from = 1
let to = 5
let tid1 = setInterval(printNumbers, 1000)
function printNumbers() {
	if (from > to) clearInterval(tid1)
	else console.log(from++)
}

// setTimeout
let from1 = 1
let to2 = 5
let tid2 = setTimeout(function fn() {
	if (from1 > to2) {
		clearTimeout(tid2)
	} else {
		console.log(from1++)
		tid2 = setTimeout(fn, 1000)
	}
}, 1000)
